package com.android.shop.adapter;

import java.util.List;

import com.android.shop.R;
import com.android.shop.bean.OrderDetailsBean;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class OrderDetailsAdapter extends BaseAdapter {
	private List<OrderDetailsBean> items;
	private Context context;
	private LayoutInflater mInflater;
	public OrderDetailsAdapter(List<OrderDetailsBean> items,Context context){
		this.context = context;
		this.items = items;
		mInflater = LayoutInflater.from(context);
	}
	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_order_deteils, null);
			holder = new ViewHolder();

			holder.dishName_text = (TextView) convertView.findViewById(R.id.dishName_text);
			holder.dishCount_text = (TextView) convertView.findViewById(R.id.dishCount_text);
			holder.dishPrice_text = (TextView) convertView.findViewById(R.id.dishPrice_text);
			
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		OrderDetailsBean classItem = items.get(position);
		if(classItem != null){
			holder.dishName_text.setText(classItem.getDishname());
			holder.dishCount_text.setText(classItem.getCount()+"个");
			holder.dishPrice_text.setText(classItem.getPrice()+"元");
		}
		return convertView;
	}

	public class ViewHolder {
		TextView dishName_text;
		TextView dishPrice_text;
		TextView dishCount_text;
	}
}
